function parsePDB(rawtext) {
    // alert("Starting PDB Parser")
    var tframeNumber = -1;

    // Trim carriage returns
    rawtext = rawtext.replace(/\r/gm,"")

    // Remove blank lines
    rawtext = rawtext.replace(/[\s\r\n]+$/, '');

    // Generate an array of file lines
    pdbtext = rawtext.split(/\n/gm)

    var tframes = [];
    var tatoms = [];
    var tremarks = [];
    var theaders = [];
    
    // Parse each line
    for (var i=0; i<pdbtext.length; i++) {

        curline = pdbtext[i].split(/\s+/);

        // Record is the first 6 characters
        var record = curline[0]

//            if (record.match("HEADER")) {
//                //document.write("HEADER record: " + pdbtext[i] + "<br>")
//            }

        // Record atoms
        if (record.match("ATOM")) {
            //document.write("<p>ATOM record: <br>")

            tserial = curline[1];
            tname = curline[2];
            taltLoc = curline[3];
            tresName = curline[4];
            tchainID = curline[5];
            tx = curline[6];
            ty = curline[7];
            tz = curline[8];
            toccupancy = curline[9];
            ttempFactor = curline[10];
            tmass = curline[11];
            tradius = curline[12];
            tcharge = curline[13];

            var atom = {
                serial: parseFloat(tserial),
                name: tname,
                altLoc: taltLoc,
                resName: tresName,
                chainID: parseFloat(tchainID),
                x: parseFloat(tx),
                y: parseFloat(ty),
                z: parseFloat(tz),
                pos: new PhiloGL.Vec3(parseFloat(tx),parseFloat(ty),parseFloat(tz)),
                occupancy: parseFloat(toccupancy),
                tempFactor: parseFloat(ttempFactor),
                mass: parseFloat(tmass),
                radius: parseFloat(tradius),
                charge: parseFloat(tcharge),
                velocity: new PhiloGL.Vec3(0, 0, 0)
            };

            tatoms = tatoms.concat(atom);
        }
        else if (record.match("END")) {
            //alert("Atoms read, END encountered");
            tframeNumber++;
            var frame = {
                frameNumber: tframeNumber,
                potentialEnergy: null,
                atoms: tatoms
            };

            tatoms = [];

            tframes = tframes.concat(frame);
        }

        else {
            // Do nothing
        }
    }

    trajectory.frames = tframes;

    tframes = [];

    //return trajectory;
}

//            else if (record.match("REMARK")) {
//                //document.write("REMARK record: " + pdbtext[i] + "<br>")
//            }

//            else {
//                //document.write("<p>ERROR: unknown record '" + record + "'<br>Content: " + pdbtext[i] + "</p>")
//            }